package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * @author cys 模型基础适配器
 */
public abstract class MyModelBaseAdapter<T> extends BaseAdapter {

    protected List<T> list;
    protected Context context;
    protected int resourceId;

    public MyModelBaseAdapter(List<T> list, Context context,
                              int resourceId) {
        super();
        this.list = list;
        this.context = context;
        this.resourceId = resourceId;
    }

    @Override
    public int getCount() {

        return list.size();
    }

    @Override
    public T getItem(int position) {

        return list.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        return getOverrideView(position, convertView, parent);
    }

    protected View getOverrideView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(resourceId, null);

        }

        initView(convertView, position);
        return convertView;
    }

    public abstract void initView(View convertView, int position);

}
